#include "Control_Menu.h"

#include "Host.h"
#include "RendererComponent.h"

#include "Control_Menu.h"
#include "Host.h"

#include "Rect.h"

using namespace gui;

Control_Menu::Control_Menu(std::string NewName, /*float NewFrameWidth, ColorRGBA<unsigned char> NewFrameColor,*/ ColorRGBA<unsigned char> NewBackColor, Vec<2, float> NewPos, Vec<2, float> NewSize, Host& NewParentHost) :
Control_Visible(NewBackColor, NewPos, NewSize, nullptr, NewParentHost),
Name(NewName)
{
}

Control_Menu::~Control_Menu(void)
{
	for (auto Control : Controls)
		delete Control;
}

void Control_Menu::Refresh()
{
	for (auto Control : Controls)
		Control->Refresh();
}


void Control_Menu::UpdateVerticesFix(RendererComponent& Renderer)
{
	Renderer.GuiFixQuadColoredVertices[Renderer.GuiFixQuadColoredVertexCount++] = VertexPos3Col(
	(Pos.X),
	(-Pos.Y),
	Layer,
	BackColor.R, BackColor.G, BackColor.B, BackColor.A);

	Renderer.GuiFixQuadColoredVertices[Renderer.GuiFixQuadColoredVertexCount++] = VertexPos3Col(
	(Pos.X),
	(-Pos.Y - Size.Y),
	Layer,
	BackColor.R, BackColor.G, BackColor.B, BackColor.A);

	Renderer.GuiFixQuadColoredVertices[Renderer.GuiFixQuadColoredVertexCount++] = VertexPos3Col(
	(Pos.X + Size.X),
	(-Pos.Y - Size.Y),
	Layer,
	BackColor.R, BackColor.G, BackColor.B, BackColor.A);

	Renderer.GuiFixQuadColoredVertices[Renderer.GuiFixQuadColoredVertexCount++] = VertexPos3Col(
	(Pos.X + Size.X),
	(-Pos.Y),
	Layer,
	BackColor.R, BackColor.G, BackColor.B, BackColor.A);

	for (auto Control : Controls)
		Control->UpdateVerticesFix(Renderer);
}

void Control_Menu::UpdateVerticesSlow(RendererComponent& Renderer)
{
	for (auto Control : Controls)
		Control->UpdateVerticesSlow(Renderer);
}

void Control_Menu::MouseMove()
{
	for (auto Control : Controls)
		if (Control->CheckIntersection())
			Control->MouseMove();
}

void Control_Menu::MouseUpLeft()
{
	for (auto Control : Controls)
		if (Control->CheckIntersection())
			Control->MouseUpLeft();
}

void Control_Menu::MouseUpRight()
{
	/*
	for (auto Control : Controls)
		if (Control->CheckIntersection())
		{
			Control->MouseDownLeft(Mouse);
			return;
		}*/
}

void Control_Menu::AddControl(Control_Base* NewControl)
{
	Controls.push_back(NewControl);
}

void Control_Menu::MouseDownLeft()
{
	for (auto Control : Controls)
		if (Control->CheckIntersection())
			Control->MouseDownLeft();
}

void Control_Menu::MouseDownRight()
{

	for (auto Control : Controls)
		if (Control->CheckIntersection())
			Control->MouseDownRight();
}

void Control_Menu::MouseWheelMove()
{
}

void Control_Menu::TextEntered()
{
}

